home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Memory C Library Procedures Memory
-
-
-
- _________________________________________________________________
-
- NNAAMMEE
- ckalloc, memory, ckfree, Tcl_DisplayMemory, Tcl_InitMemory,
- Tcl_ValidateAllMemory - Validated memory allocation inter-
- face.
-
- SSYYNNOOPPSSIISS
- mmeemmoorryy iinnffoo
- mmeemmoorryy ttrraaccee [oonn||ooffff]
- mmeemmoorryy vvaalliiddaattee [oonn||ooffff]
- mmeemmoorryy ttrraaccee__oonn__aatt__mmaalllloocc _n_n_n
- mmeemmoorryy bbrreeaakk__oonn__mmaalllloocc _n_n_n
- mmeemmoorryy ddiissppllaayy _f_i_l_e
-
-
- ##iinncclluuddee <<ttccll..hh>> or <<cckkaalllloocc..hh>>
-
- char *
- cckkaalllloocc (_s_i_z_e)
-
- void
- cckkffrreeee (_p_t_r)
-
- void
- TTccll__DDiissppllaayyMMeemmoorryy (fileName)
-
- void
- TTccll__IInniittMMeemmoorryy (_i_n_t_e_r_p)
-
- void
- TTccll__VVaalliiddaatteeAAllllMMeemmoorryy (_f_i_l_e, _l_i_n_e)
-
- AARRGGUUMMEENNTTSS
- uint _s_i_z_e (in) The size of the memory
- block to be allocated.
-
- char *_p_t_r (in) The address of a block to
- free, as returned by
- ckalloc.
-
- Tcl_Interp *_i_n_t_e_r_p (in) A pointer to the Tcl
- interpreter.
-
- char *_f_i_l_e (in) The filename of the
- caller of
- Tcl_ValidateAllMemory.
-
- int _l_i_n_e (in) The line number of the
- caller of
- Tcl_ValidateAllMemory.
-
-
-
-
- Sprite v1.0 1
-
-
-
-
-
-
- Memory C Library Procedures Memory
-
-
-
- char *_f_i_l_e_N_a_m_e (in) File to display list of
- active memory.
- _________________________________________________________________
-
-
- DDEESSCCRRIIPPTTIIOONN
- The macro cckkaalllloocc allocates memory, in the same manner as
- mmaalllloocc, with the following differences: One, cckkaalllloocc checks
- the value returned from mmaalllloocc (it calls mmaalllloocc for you) and
- panics if the allocation request fails. Two, if enabled at
- compile time, a version of cckkaalllloocc with special memory
- debugging capabilities replaces the normal version of cckkaall--
- lloocc, which aids in detecting memory overwrites and leaks
- (repeated allocations not matched by corresponding frees).
-
- cckkffrreeee frees memory allocated by cckkaalllloocc. Like cckkaalllloocc,
- when memory debugging is enabled, cckkffrreeee has enhanced capa-
- bilities for detecting memory overwrites and leaks.
-
- It is very important that you use cckkaalllloocc when you need to
- allocate memory, and that you use cckkffrreeee to free it. Should
- you use mmaalllloocc to allocate and cckkffrreeee to free, spurious
- memory validation errors will occur when memory debugging is
- enabled. Should you use ffrreeee to free memory allocated by
- cckkaalllloocc, memory corruption will occur when memory debugging
- is enabled. Any memory that is to be become the property of
- the Tcl interpreter, such as result space, must be allocated
- with cckkaalllloocc. If it is absolutely necessary for an applica-
- tion to pass back mmaalllloocced memory to Tcl, it will work only
- if Tcl is complied with the TTCCLL__MMEEMM__DDEEBBUUGG flag turned off.
- If you convert your application to use this facility, it
- will help you find memory over runs and lost memory. Note
- that memory allocated by a C library routine requiring free-
- ing should still be freed with ffrreeee, since it calls mmaalllloocc
- rather than cckkaalllloocc to do the allocation.
-
- FFIINNDDIINNGG MMEEMMOORRYY LLEEAAKKSS
- The function TTccll__DDiissppllaayyMMeemmoorryy will display a list of all
- currently allocated memory to the specified file. The fol-
- lowing information is displayed for each allocated block of
- memory: starting and ending addresses (excluding guard
- zone), size, source file where cckkaalllloocc was called to allo-
- cate the block and line number in that file. It is espe-
- cially useful to call TTccll__DDiissppllaayyMMeemmoorryy after the Tcl inter-
- preter has been deleted.
-
- EENNAABBLLIINNGG MMEEMMOORRYY DDEEBBUUGGGGIINNGG
- To enable memory debugging, Tcl should be recompiled from
- scratch with TTCCLL__MMEEMM__DDEEBBUUGG defined. This will also compile
- in a non-stub version of TTccll__IInniittMMeemmoorryy to add the mmeemmoorryy
- command to Tcl.
-
-
-
-
- Sprite v1.0 2
-
-
-
-
-
-
- Memory C Library Procedures Memory
-
-
-
- TTCCLL__MMEEMM__DDEEBBUUGG must be either left defined for all modules or
- undefined for all modules that are going to be linked
- together. If they are not, link errors will occur, with
- either TTccllDDbbCCkkffrreeee and TTccll__DDbbCCkkaalllloocc or TTccll__CCkkaalllloocc and
- TTccll__CCkkffrreeee being undefined.
-
- GGUUAARRDD ZZOONNEESS
- When memory debugging is enabled, whenever a call to cckkaalllloocc
- is made, slightly more memory than requested is allocated so
- the memory debugging code can keep track of the allocated
- memory, and also eight-byte ``guard zones'' are placed in
- front of and behind the space that will be returned to the
- caller. (The size of the guard zone is defined by the C
- #define GGUUAARRDD__SSIIZZEE in _b_a_s_e_l_i_n_e/_s_r_c/_c_k_a_l_l_o_c._c -- it can be
- extended if you suspect large overwrite problems, at some
- cost in performance.) A known pattern is written into the
- guard zones and, on a call to cckkffrreeee, the guard zones of the
- space being freed are checked to see if either zone has been
- modified in any way. If one has been, the guard bytes and
- their new contents are identified, and a ``low guard
- failed'' or ``high guard failed'' message is issued. The
- ``guard failed'' message includes the address of the memory
- packet and the file name and line number of the code that
- called cckkffrreeee. This allows you to detect the common sorts
- of one-off problems, where not enough space was allocated to
- contain the data written, for example.
-
- TTHHEE MMEEMMOORRYY CCOOMMMMAANNDD
- mmeemmoorryy _o_p_t_i_o_n_s
- The Tcl mmeemmoorryy command gives the Tcl developer control
- of Tcl's memory debugging capabilities. The memory
- command has several suboptions, which are described
- below. It is only available when Tcl has been compiled
- with memory debugging enabled.
-
- mmeemmoorryy iinnffoo
- Produces a report containing the total allocations and
- frees since Tcl began, the current packets allocated
- (the current number of calls to cckkaalllloocc not met by a
- corresponding call to cckkffrreeee), the current bytes allo-
- cated, and the maximum number of packets and bytes
- allocated.
-
- mmeemmoorryy ttrraaccee [oonn||ooffff]
- Turns memory tracing on or off. When memory tracing is
- on, every call to cckkaalllloocc causes a line of trace infor-
- mation to be written to _s_t_d_e_r_r, consisting of the word
- _c_k_a_l_l_o_c, followed by the address returned, the amount
- of memory allocated, and the C filename and line number
- of the code performing the allocation, for example...
-
- cckkaalllloocc 4400ee447788 9988 ttccllPPrroocc..cc 11440066
-
-
-
- Sprite v1.0 3
-
-
-
-
-
-
- Memory C Library Procedures Memory
-
-
-
- Calls to cckkffrreeee are traced in the same manner, except
- that the word _c_k_a_l_l_o_c is replaced by the word _c_k_f_r_e_e.
-
- mmeemmoorryy vvaalliiddaattee [oonn||ooffff]
- Turns memory vaidation on or off. When memory valida-
- tion is enabled, on every call to cckkaalllloocc or cckkffrreeee,
- the guard zones are checked for every piece of memory
- currently in existence that was allocated by cckkaalllloocc.
- This has a large performance impact and should only be
- used when overwrite problems are strongly suspected.
- The advantage of enabling memory validation is that a
- guard zone overwrite can be detected on the first call
- to cckkaalllloocc or cckkffrreeee after the overwrite occurred,
- rather than when the specific memory with the overwrit-
- ten guard zone(s) is freed, which may occur long after
- the overwrite occurred.
-
- mmeemmoorryy ttrraaccee__oonn__aatt__mmaalllloocc _n_n_n
- Enable memory tracing after _n_n_n cckkaallllooccss have been per-
- formed. For example, if you enter mmeemmoorryy
- ttrraaccee__oonn__aatt__mmaalllloocc 110000, after the 100th call to cckkaall--
- lloocc, memory trace information will begin being
- displayed for all allocations and frees. Since there
- can be a lot of memory activity before a problem
- occurs, judicious use of this option can reduce the
- slowdown caused by tracing (and the amount of trace
- information produced), if you can identify a number of
- allocations that occur before the problem sets in. The
- current number of memory allocations that have occured
- since Tcl started is printed on a guard zone failure.
-
- mmeemmoorryy bbrreeaakk__oonn__mmaalllloocc _n_n_n
- After the nnnnnn allocations have been performed, cckkaallllooccss
- output a message to this effect and that it is now
- attempting to enter the C debugger. Tcl will then
- issue a _S_I_G_I_N_T signal against itself. If you are run-
- ning Tcl under a C debugger, it should then enter the
- debugger command mode.
-
- mmeemmoorryy ddiissppllaayy _f_i_l_e
- Write a list of all currently allocated memory to the
- specified file.
-
- DDEEBBUUGGGGIINNGG DDIIFFFFIICCUULLTT MMEEMMOORRYY CCOORRRRUUPPTTIIOONN PPRROOBBLLEEMMSS
- Normally, Tcl compiled with memory debugging enabled will
- make it easy to isolate a corruption problem. Turning on
- memory validation with the memory command can help isolate
- difficult problems. If you suspect (or know) that corrup-
- tion is occurring before the Tcl interpreter comes up far
- enough for you to issue commands, you can set MMEEMM__VVAALLIIDDAATTEE
- define, recompile tclCkalloc.c and rebuild Tcl. This will
- enable memory validation from the first call to cckkaalllloocc,
-
-
-
- Sprite v1.0 4
-
-
-
-
-
-
- Memory C Library Procedures Memory
-
-
-
- again, at a large performance impact.
-
- If you are desperate and validating memory on every call to
- cckkaalllloocc and cckkffrreeee isn't enough, you can explicitly call
- TTccll__VVaalliiddaatteeAAllllMMeemmoorryy directly at any point. It takes a
- _c_h_a_r * and an _i_n_t which are normally the filename and line
- number of the caller, but they can actually be anything you
- want. Remember to remove the calls after you find the prob-
- lem.
-
- KKEEYYWWOORRDDSS
- ckalloc, ckfree, free, memory, malloc
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sprite v1.0 5
-
-
-
-